package com.bw.bargain.controller;

import java.util.Arrays;
import java.util.Map;

import com.bw.common.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bw.bargain.entity.BargainEntity;
import com.bw.bargain.service.BargainService;
import com.bw.common.utils.PageUtils;
import com.bw.common.utils.R;



/**
 * 砍价商品表
 *
 * @author Hao_YunKai
 * @email 2745578447@qq.com
 * @date 2022-03-10 19:02:50
 */
@RestController
@RequestMapping("bargain/bargain-activity")
public class BargainController {
    @Autowired
    private BargainService bargainService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bargainService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{bargainId}")
    public R info(@PathVariable("bargainId") Long bargainId){
		BargainEntity bargain = bargainService.getById(bargainId);

        return R.ok().put("bargain", bargain);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BargainEntity bargain){
		bargainService.save(bargain);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody BargainEntity bargain){
		bargainService.updateById(bargain);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] bargainIds){
		bargainService.removeByIds(Arrays.asList(bargainIds));

        return R.ok();
    }

    public static void main(String[] args) {
        long l = new IdWorker().nextId();
        System.out.println(l);
    }

}
